#include "dominion.c"
#include "assert.h"
#include "stdio.h"
#include "rngs.c"

void checkSmithyCardPlay( struct gameState *state);

int main(){
	int *cards = kingdomCards(7,8,9,10,11,12,13,14,15,16);
	struct gameState *state = newGame();
	
	initializeGame(4, cards, -1, state);
	
	for (int i = 0; i < 5; i++){
		checkSmithyCardPlay( state );
	}
	
	return 0;
}

void checkSmithyCardPlay( struct gameState *state){
	// Only player 0 has cards in hand at start.
	int player = 0;

	int newCards;
	int card = smithy;
	int discard = state->discardCount[player];
	int deck = state->deckCount[player];
	int hand = state->handCount[player];

	// We need to replace one of the current cards with a smithy randomly
	int handPos = (int)(Random() * state->handCount[player]);
	state->hand[player][handPos] = card;
	
	cardEffect(card, 0, 0, 0, state, handPos, 0);
	
	// If there were less than three cards, the player gained that many cards
	if (discard + deck < 3){ // Remember, the discard gets shuffled in
		newCards = deck + discard;
	} else {
		newCards = 3;
	}
	
	if ( hand + newCards - 1 != state->handCount[player] ){ // -1 because of Smithy leaving the hand
		printf("Hand size mismatch! Old size: %d. New size: %d. Cards drawn: %d\n", hand, state->handCount[player], newCards);
		assert(0);
	}
	
	if ( discard + deck - newCards != state->deckCount[player] + state->discardCount[player]) {
		printf("Card amount mismatch in discard + deck! Previous total: %d. New total: %d. Drawn: %d\n", discard + deck, state->deckCount[player] + state->discardCount[player], newCards);
		assert(0);
	}
	
	int total = discard + deck + hand;
	int newTotal = 	state->discardCount[player] +
			state->deckCount[player] +
			state->handCount[player];
	
		// Total sum of cards in deck, discard and hand decreases by 1 because Smithy goes into play
	if ( total != newTotal + 1 ) {
		printf("Total number of cards changed! Previous total: %d. New total: %d\n", total, newTotal);
		assert(0);	
	}
}